package pwd.allen;

import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;
import org.apache.shardingsphere.shardingjdbc.api.yaml.YamlShardingDataSourceFactory;
import org.springframework.core.io.ClassPathResource;

import javax.sql.DataSource;

/**
 * @author 门那粒沙
 * @create 2020-06-27 14:43
 **/
public class MyDataSourceFactory extends UnpooledDataSourceFactory {
    @Override
    public DataSource getDataSource() {

        // 获取数据源对象
        try {
            dataSource = YamlShardingDataSourceFactory.createDataSource(new ClassPathResource("shardingsphere.yml").getFile());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dataSource;
    }
}
